package com.cskaoyan.market.admin.service.impl;

import com.cskaoyan.market.admin.service.AdminRoleService;
import com.cskaoyan.market.db.domain.MarketRole;
import com.cskaoyan.market.db.mapper.MarketRoleMapper;
import com.cskaoyan.market.db.vo.LabelValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminRoleServiceImpl implements AdminRoleService {
    @Autowired
    private MarketRoleMapper roleMapper;

    @Override
    public List<LabelValue> options() {
        // 获取连接
        
        // 创建示例对象/获取查询数据
        List<MarketRole> marketRoles = roleMapper.selectByExample(null);
        // 创建返回对象
        List<LabelValue> roleLabelValue = new ArrayList<>();
        // 遍历，将查询数据转换至返回对象
        for (MarketRole marketRole : marketRoles) {
            LabelValue labelValue = new LabelValue();
            labelValue.setValue(marketRole.getId());
            labelValue.setLabel(marketRole.getName());
            roleLabelValue.add(labelValue);
        }
        
        return roleLabelValue;
    }
}
